<link rel="stylesheet" type="text/css" href="__PUBLIC__/plugin/dataTables/media/css/jquery.dataTables.min.css">
<script type="text/javascript" src="__PUBLIC__/plugin/dataTables/media/js/jquery.dataTables.min.js"></script>
<div class="search" >
    <input type="text" name="keyword" class="input-m" value="{$keyword}" id="keyword" placeholder="请输入产品ID或者名称">
    <select name="status" id="status">
      <option value="全部" <if condition="$status eq '全部'">selected</if>>全部</option>
      <option value="1" <if condition="$status eq '1'">selected</if>>已启用</option>
      <option value="0" <if condition="$status eq '0'">selected</if>>已停用</option>
    </select>
    <select name="type" id="type">
      <option value="全部" <if condition="$type eq '全部'">selected</if>>全部</option>
      <option value="1" <if condition="$type eq '1'">selected</if>>自由行</option>
      <option value="2" <if condition="$type eq '2'">selected</if>>当地游</option>
      <option value="3" <if condition="$type eq '3'">selected</if>>特殊产品</option>
    </select>
    <input type="button" class="button-green" value="查  询" onClick="Request()">
</div>
<div class="operate2">
  <ul>
    <li onclick="window.location='{:U(MODULE_NAME.'/Product/selladd')}'"><span class="icon-add01"></span>添加产品</li>
    <li onclick="window.location='{:U(MODULE_NAME.'/Product/visalist')}'"><span class="icon-add01"></span>添加签证产品</li>
  </ul>
  <div class="clear"></div>
</div>
<table class="list" id="dataTables">
		<thead>
  		<tr>
        <th>产品ID</th>
        <th>产品库编号</th>
        <th>图片</th>
        <th>标题</th>
        <th>主站分类</th>
        <th>产品类型</th>
        <th>发布时间</th>
        <th>状态</th>
        <th>操作</th>
      </tr>
		</thead>
         <tbody>
		<foreach name='list' item='v'>
        <tr>
           <td>{$v.id}</td>
           <td>{$v.libraryProductID}</td>
            <td>
              <img src="<if condition='$v.litPic eq null'>__PUBLIC__/image/product.jpg<else/>{$v.litPic}</if>" width="220" />
           </td>
           <td class="title" >{$v.title}<!-- <if condition="$v.recommend eq 1"><span style="color:#FF0000;">[今日推荐]</span></if> --></td>
           <td>{$v.categoryName}</td>
           <td><if condition="$v.type eq '1'">自由行<elseif condition="$v.type eq '2'" />当地游<else/></if></td>
           <td>{$v.dateLine|date='Y-m-d H:i:s',###}</td>
           <td><if condition="$v.status eq 1"><font class="font-green">启用</font><else /><font class="red">停用</font></if></td>
           <td>
               <if condition="$v.status eq '1'">
                <a href="javascript:;" onclick="toConfirm('{:U(MODULE_NAME.'/Product/sellStatusSet',array('id' => $v['id'],'status'=>'0'),'')}', '确实要停用此产品吗？')">停用</a>&nbsp;&nbsp;
               <else />
               <a href="javascript:;" onclick="Up('{$v['id']}','{$v['title']}')" >启用</a>
               &nbsp;&nbsp;
               </if>
               <a href="__URL__/Product/details/id/{$v['id']}"target="_blank">查看</a>&nbsp;&nbsp;

                <if condition="($v.type eq '1') OR ($v.type eq '2')">
                <a href="{:U(MODULE_NAME.'/Product/selledit',array('id' => $v['id']), '')}">编辑</a>&nbsp;&nbsp;
                <elseif condition="$v.type eq '4'" />
                <a href="{:U(MODULE_NAME.'/Product/customEdit',array('id' => $v['id']), '')}">编辑</a>&nbsp;&nbsp;
                <else/>
                <a href="{:U(MODULE_NAME.'/Product/selledit',array('id' => $v['id']), '')}">编辑</a>&nbsp;&nbsp;
                </if>

               <a href="javascript:;" onclick="toConfirm('{:U(MODULE_NAME.'/Product/sellproductdel',array('id' => $v['id']), '')}', '确实要删除吗？')">删除</a>&nbsp;&nbsp;
           </td>
       </tr>
      </foreach>
 </tbody>
</table>
<!-- <div class="page" style="clear: both;">{$page}</div> -->
<script type="text/javascript">
$(document).ready(function () {
    $('#dataTables').dataTable({
      // paging: false,
      // scrollY: 400,
      order: [[ 1, "desc" ]],
      columnDefs: [ {
          targets: 8,
          orderable: false  //如果第一列进行排序，有相同数据则按照第二列顺序排列
        } ],
      language: {
          "sProcessing": "处理中...",
          "sLengthMenu": "显示 _MENU_ 项结果",
          "sZeroRecords": "没有匹配结果",
          "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
          "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
          "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
          "sInfoPostFix": "",
          "sSearch": "高级搜索:",
          "sUrl": "",
          "sEmptyTable": "表中数据为空",
          "sLoadingRecords": "载入中...",
          "sInfoThousands": ",",
          "oPaginate": {
              "sFirst": "首页",
              "sPrevious": "上页",
              "sNext": "下页",
              "sLast": "末页"
          },
          "oAria": {
              "sSortAscending": ": 以升序排列此列",
              "sSortDescending": ": 以降序排列此列"
          }
      }
    });

});
  /**
   * [Up description]
   * @param {[type]} id    [description]
   * @param {[type]} title [description]
   */
  function Up(id,title)
  {
    $.ajax({
      url: '{:U(MODULE_NAME.'/Product/checkDepartureAjax')}',
      type: 'POST',
      dataType: 'json',
      data: {'productID': id},
      success:function  (data) {

        if(data.valid == true)
        { 
          var Div = layer.open({
              type: 1,
              title: '产品上架',
              area: ['450px', '200px'],
              shift: 0, //从左动画弹出
              content: '<div class="layer-content"><form method="post" id="layerDiv" name="form_do" action="/Home/Product/sellStatusSet.html"><p>你现在上架的是：'+title+'</p><p>下架时间：<input class="Wdate" type="text" style="width:120px;padding:2px 5px;" onclick="WdatePicker()" name="endDate" value=""><input type="hidden" name="id" value="'+id+'"><input type="hidden" name="status" value="1"></p></form></div>',
              btn:['确定','取消'],
              yes: function(index){
                $('#layerDiv').submit();
              },
              cancel: function(){
                layer.close(Div);
              }
          });
        }
        else
        {
          layer.msg(data.state);
          return;
        }
      }
    })

  }

  /**
   * [Request description]
   */
  function Request()
  {
    var url = '';
        url+= '?';
        url+= 'keyword='+$('#keyword').val();
        url+= '&status='+$('#status').val();
        url+= '&type='+$('#type').val();
    window.location.href = '/Product/sell.html'+url;
  }
</script>